package com.yj.ccs.abs.common.controller;

import com.yj.ccs.abs.common.dto.CodeDto;
import com.yj.ccs.abs.common.entity.Region;
import com.yj.ccs.abs.common.model.BaseResult;
import com.yj.ccs.abs.common.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/15
 * Author     : Unbelievable9
 **/
@Api(tags = "Region-Controller")
@RestController
@RequestMapping("/region")
public class RegionController {

    @Autowired
    RegionService regionService;

    @ApiOperation("获取所有省份信息")
    @GetMapping("/list-province")
    public ResponseEntity<BaseResult> listProvince() {
        return new ResponseEntity<>(BaseResult.success("获取所有省份信息成功").setData(regionService.getAllProvinces()), HttpStatus.OK);
    }

    @ApiOperation("根据省份编号获取所有城市信息")
    @GetMapping("/list-city")
    public ResponseEntity<BaseResult> listCity(@Validated CodeDto codeDto) {
        return new ResponseEntity<>(BaseResult.success("根据省份编号获取所有城市信息成功").setData(regionService.getAllCitiesByProvinceCode(codeDto.getCode())), HttpStatus.OK);
    }

    @ApiOperation("根据城市编号获取所有区县信息")
    @GetMapping("/list-area")
    public ResponseEntity<BaseResult> listArea(@Validated CodeDto codeDto) {
        return new ResponseEntity<>(BaseResult.success("根据城市编号获取所有区县信息成功").setData(regionService.getAllAreasByCityCode(codeDto.getCode())), HttpStatus.OK);
    }

    @ApiOperation("/根据区县编号获取完整三级城市信息")
    @GetMapping("/get-region-info")
    public ResponseEntity<BaseResult> getRegionInfo(@Validated CodeDto codeDto) {
        Region region = regionService.getRegionByAreaCode(codeDto.getCode());

        return new ResponseEntity<>(BaseResult.success("获取三级城市信息成功").setData(region), HttpStatus.OK);
    }
}
